package com.youbug.mall.member_ums.feign.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.youbug.common.vo.MemberAddressVo;
import com.youbug.mall.member_ums.entity.UmsMemberReceiveAddress;
import com.youbug.mall.member_ums.service.IUmsMemberReceiveAddressService;
import com.youbug.mall.order_oms.feign.IOrderMemberFeignService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

@Service
public class OrderFeignServiceImpl implements IOrderMemberFeignService {

    @Autowired
    private IUmsMemberReceiveAddressService memberReceiveAddressService;

    @Override
    public List<MemberAddressVo> getAddress(long memberId) {

        List<UmsMemberReceiveAddress> addresses = memberReceiveAddressService
                .list(new QueryWrapper<UmsMemberReceiveAddress>().eq("member_id", memberId));
        if(!CollectionUtils.isEmpty(addresses)){
            List<MemberAddressVo> vos = new ArrayList<>(addresses.size());
            for (UmsMemberReceiveAddress address : addresses) {
                MemberAddressVo addressVo = new MemberAddressVo();
                BeanUtils.copyProperties(address, addressVo);
                vos.add(addressVo);
            }
            return vos;
        }
        return null;
    }
}
